package com.scenic.rd_android.design_model.mvp.model.data;

import com.scenic.rd_android.design_model.mvp.model.Task;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by scenic on 16/8/20.
 */
public class TaskRepository implements TaskDataSource{
    TaskDataSource remote;
    TaskDataSource local;

    Map<String , Task> mCache = new HashMap<>();

    @Override
    public void saveTask(Task task) {
        mCache.put(task.getId(),task);
    }

    @Override
    public void deleteTask(String taskID) {
        mCache.remove(mCache.get(taskID));
    }

    @Override
    public void getTasks(LocalTasksCallback callback) {
        callback.onTasksLoaded(new ArrayList<>(mCache.values()));
    }

    @Override
    public void getTask(final String taskID, GetTaskCallback callback) {
        callback.onTaskLoad(mCache.get(taskID));
    }
}
